# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def detectCycle(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        fast = head
        slow = head
        while fast and slow:
            fast = fast.next
            if not fast: return None
            fast = fast.next
            if not fast: return None
            slow = slow.next
            if fast==slow:
                break
        entry = head
        while entry is not slow:
            entry = entry.next
            slow = slow.next
        return entry